window.onload=function(){
	inputfocus();
	mailcheck();
	checkPhone();
	checkpassword();
}
function inputfocus(){
	var array=[];
	array=document.getElementsByTagName('input');
	for (var i = 0; i < array.length-1; i++) {
		array[i].onfocus=function(){
			this.value="";
			this.style.color="black";
			if(this.name=="password"||this.name=="affpassword")
			{
				this.type="password";
			}
		}
	}
}

function mailcheck(){
	var sText = document.getElementById('email').value;
	document.getElementById('email').onblur = function sValue(){
		sText = this.value;
		var reMail =/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/;

		var s=new RegExp(reMail);

		if(!s.test(sText))
			{
				alert('邮箱格式不正确');
				return false;
			}
			else{
				return true;
			}
	}
}

function checkPhone(){ 
    document.getElementById('phoneNumber').onblur = function(){
    var phone = document.getElementById('phoneNumber').value;
    var reg = /^1[0-9]{10}$/;
    if(!reg.test(phone)){ 
        alert("手机号码有误，请重填!");  
     	   return false;
  						}  	
  		else{
				return true;
			}	
    }
}
function checkpassword(){
	document.getElementById('affpassword').onblur=function () {
	var password=document.getElementById('password').value;
	var affpassword=document.getElementById('affpassword').value;
	if(password!=affpassword)
	{
		alert("密码不一致！");
	}
	}
}

function register() {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/register',
		type: 'POST',
		dataType: 'json',
		data: $('#user').serialize(),
		success:function(result){
			if(result.status=='200'){
				alert('注册成功！');
				window.location.href="../user/login.html";
			}
		}
	});
	
	
}